CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(cmark)

#
# Determine exact CPU type as on Apple Mac OS X platform we always
# get i386 from CMake, even if it's x86_64
#

IF (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86|x86_64)$")
	INCLUDE(CheckTypeSize)
	CHECK_TYPE_SIZE("void*" SIZEOF_VOID_P BUILTIN_TYPES_ONLY)
	IF (${SIZEOF_VOID_P} EQUAL 8)
		SET(CMAKE_SYSTEM_PROCESSOR x86_64)
	ELSE()
		SET(CMAKE_SYSTEM_PROCESSOR i386)
	ENDIF()
ENDIF()

#
# Show OS version and platform
#

MESSAGE(STATUS "Configuration: " ${CMAKE_BUILD_TYPE})
MESSAGE(STATUS "System: " ${CMAKE_SYSTEM_NAME} " " ${CMAKE_SYSTEM_VERSION})
MESSAGE(STATUS "Processor: " ${CMAKE_SYSTEM_PROCESSOR})

#
# Set compiler flags
#

SET(CMAKE_C_FLAGS "-Wall")

# Set platform-specific flags
IF (${WIN32})
	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qstd=c99")
ELSE (${WIN32})
	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -D_BSD_SOURCE -D_GNU_SOURCE -D_DARWIN_C_SOURCE -D_POSIX_C_SOURCE=2")

	SET(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
	SET(CMAKE_C_FLAGS_DEBUG "-g")
ENDIF (${WIN32})
MESSAGE(STATUS "Compiler flags: " ${CMAKE_C_FLAGS})

# Set platform version
SET(CMARK_VENDOR "Open Source Technologies")
SET(CMARK_VERSION_MAJOR 0)
SET(CMARK_VERSION_MINOR 1)
SET(CMARK_VERSION_PATCH 0)

#
# Check platform features
#

INCLUDE(CheckIncludeFile)

# Check for *NIX headers
CHECK_INCLUDE_FILE("stdbool.h" HAVE_STDBOOL_H)
CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)

#
# Setup project
#

ENABLE_TESTING()

INCLUDE_DIRECTORIES(
	${PROJECT_SOURCE_DIR}/include
	${PROJECT_SOURCE_DIR}/src
)
SET(SOURCES
	"src/cmark.c"
	"src/lexer.c"
	"src/token.c"
)

#
# Configure build
#

CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/src/config.h.in" "${PROJECT_SOURCE_DIR}/src/config.h")

ADD_EXECUTABLE(cmark ${SOURCES})
